package websockettest;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

import java.net.InetSocketAddress;

/**
 * @author RJA
 * @version V1.0
 * @Title: websockettest.demo_1
 * @Description:
 * @date 2019/7/12 16:57
 */
public class WebSocketServer {
    public static void main(String[] args) {
        EventLoopGroup bossGroup = new NioEventLoopGroup();//从客户端接收链接，但不作处理
        EventLoopGroup workerGroup = new NioEventLoopGroup();//处理链接后续的处理

        ServerBootstrap serverBootstrap = new ServerBootstrap();//轻松启动服务端代码
        serverBootstrap.group(bossGroup,workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new WebSocketInitializer());
        try {
            ChannelFuture future = serverBootstrap.bind(new InetSocketAddress(8899)).sync();
            future.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
